<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="月票账单流水号" prop="monthTicketBillId">
        <el-input
          v-model="queryParams.monthTicketBillId"
          placeholder="请输入月票账单流水号"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="第三方订单号，不得超过30个字符" prop="billCode">
        <el-input
          v-model="queryParams.billCode"
          placeholder="请输入第三方订单号，不得超过30个字符"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="停车场编号列表" prop="parkCodes">
        <el-input
          v-model="queryParams.parkCodes"
          placeholder="请输入停车场编号列表"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="开通成功时返回的月票id" prop="monthTicketId">
        <el-input
          v-model="queryParams.monthTicketId"
          placeholder="请输入开通成功时返回的月票id"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="票原总价，单位元" prop="originPrice">
        <el-input
          v-model="queryParams.originPrice"
          placeholder="请输入票原总价，单位元"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="票折后总价，单位元" prop="favorPrice">
        <el-input
          v-model="queryParams.favorPrice"
          placeholder="请输入票折后总价，单位元"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="支付来源，参考附录" prop="payOrigin">
        <el-select v-model="queryParams.payOrigin" placeholder="请选择支付来源，参考附录" clearable size="small">
          <el-option
            v-for="dict in payOriginOptions"
            :key="dict.dictValue"
            :label="dict.dictLabel"
            :value="dict.dictValue"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="支付来源备注" prop="payOriginRemark">
        <el-input
          v-model="queryParams.payOriginRemark"
          placeholder="请输入支付来源备注"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="支付方式，参考附录" prop="payMode">
        <el-select v-model="queryParams.payMode" placeholder="请选择支付方式，参考附录" clearable size="small">
          <el-option
            v-for="dict in payModeOptions"
            :key="dict.dictValue"
            :label="dict.dictLabel"
            :value="dict.dictValue"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="支付方式备注" prop="payModeRemark">
        <el-input
          v-model="queryParams.payModeRemark"
          placeholder="请输入支付方式备注"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="续费人" prop="renewBy">
        <el-input
          v-model="queryParams.renewBy"
          placeholder="请输入续费人"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="续费时间点" prop="renewTime">
        <el-date-picker clearable size="small"
          v-model="queryParams.renewTime"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="选择续费时间点">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="起始时间" prop="startTime">
        <el-date-picker clearable size="small"
          v-model="queryParams.startTime"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="选择起始时间">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="结束时间" prop="endTime">
        <el-date-picker clearable size="small"
          v-model="queryParams.endTime"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="选择结束时间">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="添加 时间" prop="createtime">
        <el-date-picker clearable size="small"
          v-model="queryParams.createtime"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="选择添加 时间">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="修改时间" prop="updatetime">
        <el-date-picker clearable size="small"
          v-model="queryParams.updatetime"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="选择修改时间">
        </el-date-picker>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['system:parkTicketRenew:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['system:parkTicketRenew:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['system:parkTicketRenew:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
		  :loading="exportLoading"
          @click="handleExport"
          v-hasPermi="['system:parkTicketRenew:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="parkTicketRenewList" border size="mini" stripe @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="主键id" align="center" prop="id" v-if="false"/>
      <el-table-column label="月票账单流水号" align="center" prop="monthTicketBillId" />
      <el-table-column label="第三方订单号，不得超过30个字符" align="center" prop="billCode" />
      <el-table-column label="停车场编号列表" align="center" prop="parkCodes" />
      <el-table-column label="开通成功时返回的月票id" align="center" prop="monthTicketId" />
      <el-table-column label="票原总价，单位元" align="center" prop="originPrice" />
      <el-table-column label="票折后总价，单位元" align="center" prop="favorPrice" />
      <el-table-column label="支付来源，参考附录" align="center" prop="payOrigin" :formatter="payOriginFormat" />
      <el-table-column label="支付来源备注" align="center" prop="payOriginRemark" />
      <el-table-column label="支付方式，参考附录" align="center" prop="payMode" :formatter="payModeFormat" />
      <el-table-column label="支付方式备注" align="center" prop="payModeRemark" />
      <el-table-column label="备注" align="center" prop="remark" />
      <el-table-column label="续费人" align="center" prop="renewBy" />
      <el-table-column label="续费时间点" align="center" prop="renewTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.renewTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="起始时间" align="center" prop="startTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.startTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="结束时间" align="center" prop="endTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.endTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="添加 时间" align="center" prop="createtime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.createtime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="修改时间" align="center" prop="updatetime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.updatetime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['system:parkTicketRenew:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['system:parkTicketRenew:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改月票续费记录对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="60%" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" :inline="true"  label-width="120px">
        <el-form-item label="月票账单流水号" prop="monthTicketBillId">
          <el-input v-model="form.monthTicketBillId" placeholder="请输入月票账单流水号" />
        </el-form-item>
        <el-form-item label="第三方订单号，不得超过30个字符" prop="billCode">
          <el-input v-model="form.billCode" placeholder="请输入第三方订单号，不得超过30个字符" />
        </el-form-item>
        <el-form-item label="停车场编号列表" prop="parkCodes">
          <el-input v-model="form.parkCodes" placeholder="请输入停车场编号列表" />
        </el-form-item>
        <el-form-item label="开通成功时返回的月票id" prop="monthTicketId">
          <el-input v-model="form.monthTicketId" placeholder="请输入开通成功时返回的月票id" />
        </el-form-item>
        <el-form-item label="票原总价，单位元" prop="originPrice">
          <el-input v-model="form.originPrice" placeholder="请输入票原总价，单位元" />
        </el-form-item>
        <el-form-item label="票折后总价，单位元" prop="favorPrice">
          <el-input v-model="form.favorPrice" placeholder="请输入票折后总价，单位元" />
        </el-form-item>
        <el-form-item label="支付来源，参考附录" prop="payOrigin">
          <el-select v-model="form.payOrigin" placeholder="请选择支付来源，参考附录">
            <el-option
              v-for="dict in payOriginOptions"
              :key="dict.dictValue"
              :label="dict.dictLabel"
              :value="parseInt(dict.dictValue)"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="支付来源备注" prop="payOriginRemark">
          <el-input v-model="form.payOriginRemark" placeholder="请输入支付来源备注" />
        </el-form-item>
        <el-form-item label="支付方式，参考附录" prop="payMode">
          <el-select v-model="form.payMode" placeholder="请选择支付方式，参考附录">
            <el-option
              v-for="dict in payModeOptions"
              :key="dict.dictValue"
              :label="dict.dictLabel"
              :value="parseInt(dict.dictValue)"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="支付方式备注" prop="payModeRemark">
          <el-input v-model="form.payModeRemark" placeholder="请输入支付方式备注" />
        </el-form-item>
        <el-form-item label="备注" prop="remark">
          <el-input v-model="form.remark" placeholder="请输入备注" />
        </el-form-item>
        <el-form-item label="续费人" prop="renewBy">
          <el-input v-model="form.renewBy" placeholder="请输入续费人" />
        </el-form-item>
        <el-form-item label="续费时间点" prop="renewTime">
          <el-date-picker clearable size="small"
            v-model="form.renewTime"
            type="datetime"
            value-format="yyyy-MM-dd HH:mm:ss"
            placeholder="选择续费时间点">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="起始时间" prop="startTime">
          <el-date-picker clearable size="small"
            v-model="form.startTime"
            type="datetime"
            value-format="yyyy-MM-dd HH:mm:ss"
            placeholder="选择起始时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="结束时间" prop="endTime">
          <el-date-picker clearable size="small"
            v-model="form.endTime"
            type="datetime"
            value-format="yyyy-MM-dd HH:mm:ss"
            placeholder="选择结束时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="添加 时间" prop="createtime">
          <el-date-picker clearable size="small"
            v-model="form.createtime"
            type="datetime"
            value-format="yyyy-MM-dd HH:mm:ss"
            placeholder="选择添加 时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="修改时间" prop="updatetime">
          <el-date-picker clearable size="small"
            v-model="form.updatetime"
            type="datetime"
            value-format="yyyy-MM-dd HH:mm:ss"
            placeholder="选择修改时间">
          </el-date-picker>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button :loading="buttonLoading" type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listParkTicketRenew, getParkTicketRenew, delParkTicketRenew, addParkTicketRenew, updateParkTicketRenew, exportParkTicketRenew } from "@/api/system/parkTicketRenew";

export default {
  name: "ParkTicketRenew",
  components: {
  },
  data() {
    return {
	  //按钮loading
	  buttonLoading: false,
      // 遮罩层
      loading: true,
      // 导出遮罩层
      exportLoading: false,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 月票续费记录表格数据
      parkTicketRenewList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 支付来源，参考附录字典
      payOriginOptions: [],
      // 支付方式，参考附录字典
      payModeOptions: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        monthTicketBillId: undefined,
        billCode: undefined,
        parkCodes: undefined,
        monthTicketId: undefined,
        originPrice: undefined,
        favorPrice: undefined,
        payOrigin: undefined,
        payOriginRemark: undefined,
        payMode: undefined,
        payModeRemark: undefined,
        renewBy: undefined,
        renewTime: undefined,
        startTime: undefined,
        endTime: undefined,
        createtime: undefined,
        updatetime: undefined
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      }
    };
  },
  created() {
    this.getList();
    this.getDicts("park_ticket_pay_origin").then(response => {
      this.payOriginOptions = response.data;
    });
    this.getDicts("park_ticket_pay_mode").then(response => {
      this.payModeOptions = response.data;
    });
  },
  methods: {
    /** 查询月票续费记录列表 */
    getList() {
      this.loading = true;
      listParkTicketRenew(this.queryParams).then(response => {
        this.parkTicketRenewList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 支付来源，参考附录字典翻译
    payOriginFormat(row, column) {
      return this.selectDictLabel(this.payOriginOptions, row.payOrigin);
    },
    // 支付方式，参考附录字典翻译
    payModeFormat(row, column) {
      return this.selectDictLabel(this.payModeOptions, row.payMode);
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: undefined,
        monthTicketBillId: undefined,
        billCode: undefined,
        parkCodes: undefined,
        monthTicketId: undefined,
        originPrice: undefined,
        favorPrice: undefined,
        payOrigin: undefined,
        payOriginRemark: undefined,
        payMode: undefined,
        payModeRemark: undefined,
        remark: undefined,
        renewBy: undefined,
        renewTime: undefined,
        startTime: undefined,
        endTime: undefined,
        createtime: undefined,
        updatetime: undefined
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加月票续费记录";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.loading = true;
      this.reset();
      const id = row.id || this.ids
      getParkTicketRenew(id).then(response => {
        this.loading = false;
        this.form = response.data;
        this.open = true;
        this.title = "修改月票续费记录";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          this.buttonLoading = true;
          if (this.form.id != null) {
            updateParkTicketRenew(this.form).then(response => {
              this.buttonLoading = false;
              this.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addParkTicketRenew(this.form).then(response => {
              this.buttonLoading = false;
              this.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$confirm('是否确认删除月票续费记录编号为"' + ids + '"的数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(() => {
          this.loading = true;
          return delParkTicketRenew(ids);
        }).then(() => {
          this.loading = false;
          this.getList();
          this.msgSuccess("删除成功");
        }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      const queryParams = this.queryParams;
      this.$confirm('是否确认导出所有月票续费记录数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(() => {
          this.exportLoading = true;
          return exportParkTicketRenew(queryParams);
        }).then(response => {
          this.download(response.msg);
          this.exportLoading = false;
        }).catch(() => {});
    }
  }
};
</script>
